// @FileName  :multi.c
// @Time      :2024/3/20 18:09
// @Author    :YKW
//# include <bits/stdc++.h>
//using namespace std;
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
# include <string.h>
# include <stdlib.h>

typedef struct node {
    int a, n;
    struct node *nxt;
} node;

void solve() {
    node *f1 = (node *) malloc(sizeof(node));
    node *f2 = (node *) malloc(sizeof(node));
    node *ans = (node *) malloc(sizeof(node));
    node *rec = f1, *tmp1;
    int a, n, fg = 0;
    while (~(scanf("%d%d", &a, &n))) {
        node *nxt = (node *) malloc(sizeof(node));
        rec->nxt = nxt;
        rec = rec->nxt;
        rec->nxt = NULL;
        rec->a = a;
        rec->n = n;
        if (getchar() == '\n') {
            if (fg == 0)
                fg = 1, rec = f2;
            else
                break;
        }
    }
    f1 = f1->nxt;
    f2 = f2->nxt;
    ans->nxt = NULL;
    while (f1 != NULL) {
        node *tmp2 = f2;
        tmp1 = ans;
        while (tmp2 != NULL) {
            int aa = f1->a * tmp2->a;
            int nn = f1->n + tmp2->n;
            tmp2 = tmp2->nxt;
            while (tmp1 != NULL && tmp1->nxt != NULL && tmp1->nxt->n > nn)
                tmp1 = tmp1->nxt;
            if (tmp1 == NULL || tmp1->nxt == NULL) {//尾部
                node *nd = (node *) malloc(sizeof(node));
                nd->nxt = NULL;
                nd->a = aa;
                nd->n = nn;
                tmp1->nxt = nd;
            } else if (tmp1->nxt->n == nn) tmp1->nxt->a = tmp1->nxt->a + aa;
            else {
                node *nd = (node *) malloc(sizeof(node));
                nd->nxt = tmp1->nxt;
                nd->a = aa;
                nd->n = nn;
                tmp1->nxt = nd;
            }
        }
        f1 = f1->nxt;
    }
    ans = ans->nxt;
    while (ans != NULL) {
        printf("%d %d ", ans->a, ans->n);
        ans = ans->nxt;
    }
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) solve();
    return 0;
}